package com.yanqu.road.server.logic.activity.condition.recharge;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.GetRechargeMallResult;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.estatewar.UserEstateWarData;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.gameplayer.module.player.EstateWarModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.manger.config.EstateWarConfigMgr;

import java.math.BigInteger;

/**
 * 现金礼包，乔迁
 */
public class RechargeEstateMoveFloorActivityCondition extends BaseActivityCondition {

	public RechargeEstateMoveFloorActivityCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
		super(activityInfo, activityConditionInfo, baseActivityData);
	}

	@Override
	public void addTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.RechargeEstateMoveFloor.getValue(), handle);
	}

	@Override
	public void removeTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.RechargeEstateMoveFloor.getValue(), handle);
	}

	public boolean isCompleted(GamePlayer player) {
		return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
	}

	@Override
	protected void player_BoardLevelHandle(Object object) {
		int args = (int)object;
		if(args > 0){
			//加道具，设置购买状态
			if(getValue().intValue() == args) {
				getRMBMallActivityReward(args);
			}
		}else {
			int param4 = activityConditionInfo.getParamList().get(3).intValue();
			UserEstateWarData userEstateWarData = player.getModule(EstateWarModule.class).getUserEstateWarData();
			int floorIndex = EstateWarConfigMgr.getEstateFloorIndex(userEstateWarData);
			if (floorIndex >= param4 || args == -666) {//直接触发暗号
				if (getValue().compareTo(BigInteger.ZERO) == 0) {
					GetRechargeMallResult result = player.getModule(ActivityModule.class).getShowRMBMallInfo(activityConditionInfo);
					if (result.isDuringCd() && args != -666) {
						return;
					}
					setRMBMallActivityInfo(result.getMallInfo());
				}
			}
		}
	}
}
